﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace CarolLib.Core.Helper
{
    /// <summary>
    /// 类型转换辅助类
    /// </summary>
    public class ConvertHelper
    {
        public static T1 ConvertObject<T1, T2>(T2 source)
        {
            T1 obj = (T1)EmitHelper.GetInstanceCreator(typeof(T1)).Invoke();
            foreach (PropertyInfo p in typeof(T2).GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                PropertyInfo newP = typeof(T1).GetProperty(p.Name);
                newP.SetValue(obj, p.GetValue(source, null), null);
            }
            return obj;
        }
    }
}
